import React, { useState, useCallback, useEffect } from 'react'
import { Table, Typography, Pagination, Button } from 'antd';

import { request, history } from 'umi';
export default function Tables(props: any) {
    const [flag, setFlag] = useState(false)
    const columns = [
        {
            title: '活动名称',
            dataIndex: 'activityName',
            key: 'id',
        },
        {
            title: '创建人',
            dataIndex: 'creator',
            key: 'id',
        },
        {
            title: '创建时间',
            dataIndex: 'gmtCreated',
            key: 'id',
        },
        {
            title: '活动时间',
            dataIndex: 'timeDate',
            key: 'id',
        },
        {
            title: '状态',
            dataIndex: 'activityStatus',
            key: 'id',
        },
        {
            title: '操作',
            dataIndex: 'operation',
            render: (_: any, record: any) => {
                return (
                    <>
                        {flag && <Button onClick={() => { edit(record) }}>编辑</Button>}
                        <Button onClick={() => detial(record)}>
                            详情
                        </Button>
                    </>
                );
            },
        },
    ];
    const detial = (record: any) => {
        history.push({
            pathname: "/detail",
            query: {
                record,
                title: "详情"
            }
        })
    }
    const onChange = (e: any, a: any) => {
        console.log(e, "dd")
        console.log(a, "aaa")
        props.getPages(e, a)
    }
    const edit = (record: any) => {
        history.push({
            pathname: "/createActive",
            query: {
                record,
                activityBasicId: record.activityBasicId,
                titles: "edit"
            }
        })
    }
    useEffect(() => {
        if (props.keys == "5") {
            setFlag(true)
        }
    }, [])
    return (
        <div>
            <Table
                columns={columns}
                dataSource={props.data}
                pagination={false}
            />
            <div style={{ position: "relative", marginTop: "8px" }}>
                <span style={{ position: "absolute", left: '500px', top: "5px" }}>共{props.total}条</span> <Pagination style={{ position: "absolute", right: "0px" }} showQuickJumper pageSize={props.pages.pageSize} current={props.pages.page} total={props.total} onChange={onChange} />
            </div>
        </div>
    )
}
